<?php


namespace App\backend\services;


use App\backend\models\GoodsKeywordModel;

class GoodsKeywordServices
{

    /**
     * 获取 - 商品关键词列表
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function getList($data)
    {
        $page = !isset($data['page']) ? 1 : $data['page'];unset($data['page']);
        $limit = !isset($data['limit']) ? 20 : $data['limit'];unset($data['limit']);

        $select = ['id', 'keyword'];
        $list = GoodsKeywordModel::listed($page, $limit, [], [], $select);
        return $list;
    }

    /**
     * 添加/编辑 - 商品关键词
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function goodsKeywordModify($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $id = isset($data['keyword_id']) && !empty($data['keyword_id']) ? $data['keyword_id'] : 0;unset($data['keyword_id']);

        if ($id) {
            $data['updated_at'] = time();
            $list = GoodsKeywordModel::updatedData($id, $data);
        } else {
            $data['created_at'] = time();
            $list = GoodsKeywordModel::insertData($data);
        }

        return $list;
    }

    /**
     * 删除/下架 - 商品关键词
     *
     * @param $data //请求参数数组
     * @return array
     */
    public static function goodsKeywordDelete($data)
    {
        if (empty($data) && $data == false) {
            return [];
        }

        $data['id'] = isset($data['keyword_id']) && !empty($data['keyword_id']) ? $data['keyword_id'] : 0;unset($data['keyword_id']);
        $update_data['status'] = !empty($data['status']) ? $data['status'] : 0;unset($data['status']);

        $list = GoodsKeywordModel::deleteds($data, $update_data);
        return $list;
    }

}
